<template>
  <div class="content-box">
    <!-- <el-table v-loading="loading" :data="tableData" border @cell-click="ynEditquDisAble">
      <el-table-column label="序号" align="center" prop="index" width="70">
        <template slot-scope="scope">
          {{ scope.$index + 1 + (queryParams.pageNum - 1) * queryParams.pageSize }}
        </template>
      </el-table-column>
      <el-table-column prop="siteId" align="center" label="站址编码" width="150" show-overflow-tooltip />
      <el-table-column prop="scategoryCode" align="center" label="物资编码" width="130" show-overflow-tooltip />
      <el-table-column prop="categoryName" align="center" label="物资名称" width="130" show-overflow-tooltip />
      <el-table-column prop="unit" align="center" label="计量单位" width="130" />
      <el-table-column prop="orderNo" align="center" label="采购订单号" width="250" show-overflow-tooltip />
      <el-table-column prop="supplierCode" align="center" label="供应商编码" width="110" show-overflow-tooltip />
      <el-table-column prop="supplierName" align="center" label="供应商名称" width="220" show-overflow-tooltip />
      <el-table-column prop="contractCode" align="center" label="合同编号" width="160" show-overflow-tooltip />
      <el-table-column prop="outPutTypeName" align="center" label="是否利旧资产" width="130" />
      <el-table-column prop="assetCode" align="center" label="资产编号" width="130" show-overflow-tooltip />
      <el-table-column prop="assetName" align="center" label="资产名称" width="130" show-overflow-tooltip />
      <el-table-column prop="price" align="center" label="单价（不含税）" width="130" />
      <el-table-column prop="amount" align="center" label="数量" :formatter="shineAsk" />
      <el-table-column prop="equipSum" align="center" label="合价（不含税）" width="130" :formatter="shineAsk" />
      <el-table-column prop="taxRate" align="center" label="税率" :formatter="shineAsk" />
      <el-table-column prop="taxAmount" align="center" label="税额（元）" width="90" :formatter="shineAsk" />
      <el-table-column prop="amt" align="center" label="含税总价（元）" width="110" :formatter="shineAsk" />
      <el-table-column prop="changePrice" align="center" label="变化合价" width="110" :formatter="shineAsk">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.changePrice"
            type="number"
            :disabled="ynEditquDisAbleBegin(scope.row, 'changePrice')"
            @input="changePriceInput($event, scope)"
          />
        </template>
      </el-table-column>
      <el-table-column prop="changeNum" align="center" label="调增数量" width="110">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.changeNum"
            type="number"
            :disabled="ynEditquDisAbleBegin(scope.row, 'changeNum')"
            @focus="setChangeNum($event, scope)"
            @blur="changeNumInput($event, scope)"
          />
        </template>
      </el-table-column>
      <el-table-column align="center" label="入库" width="110">
        <el-table-column prop="usableStorage" align="center" label="可用">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.usableStorage"
              type="number"
              :disabled="ynEditquDisAbleBegin(scope.row, 'usableStorage')"
              @focus="setChangeNum($event, scope)"
              @blur="usableStorageInput($event, scope, 'usableStorage')"
            />
          </template>
        </el-table-column>
        <el-table-column prop="unusableStorage" align="center" label="不可用">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.unusableStorage"
              type="number"
              :disabled="ynEditquDisAbleBegin(scope.row, 'unusableStorage')"
              @focus="setChangeNum($event, scope)"
              @blur="usableStorageInput($event, scope, 'unusableStorage')"
            />
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column align="center" label="不入库" width="110">
        <el-table-column prop="notUsableStorage" align="center" label="可用">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.notUsableStorage"
              type="number"
              :disabled="ynEditquDisAbleBegin(scope.row, 'notUsableStorage')"
              @focus="setChangeNum($event, scope)"
              @blur="usableStorageInput($event, scope, 'notUsableStorage')"
            />
          </template>
        </el-table-column>
        <el-table-column prop="notUnusableStorage" align="center" label="不可用">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.notUnusableStorage"
              type="number"
              :disabled="ynEditquDisAbleBegin(scope.row, 'notUnusableStorage')"
              @focus="setChangeNum($event, scope)"
              @blur="usableStorageInput($event, scope, 'notUnusableStorage')"
            />
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column prop="storemanName" align="center" label="保管人" width="130">
        <template slot-scope="scope">
          <el-input v-model="scope.row.storemanName" :disabled="ynEditquDisAbleBegin(scope.row, 'storemanName')" />
        </template>
      </el-table-column>
      <el-table-column prop="storemanNum" align="center" label="保管人联系方式" width="130">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.storemanNum"
            type="tel"
            :disabled="ynEditquDisAbleBegin(scope.row, 'storemanNum')"
            @input="storemanNumInput($event, scope)"
          />
        </template>
      </el-table-column>
      <el-table-column prop="storageAddress" align="center" label="实物保管地址" width="130">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.storageAddress"
            :disabled="ynEditquDisAbleBegin(scope.row, 'storageAddress')"
            @input="storageAddressInput($event, scope)"
          />
        </template>
      </el-table-column>
      <el-table-column prop="doneNum" align="center" label="变化后数量" width="130" />
      <el-table-column prop="donePrice" align="center" label="变化后合价（不含税）" width="150" :formatter="shineAsk" />
      <el-table-column prop="doneTaxAmount" align="center" label="调整后税额（元）" width="120" :formatter="shineAsk" />
      <el-table-column prop="doneAmt" align="center" label="调整后税额总价（元）" width="150" :formatter="shineAsk" />
      <el-table-column prop="status" align="center" label="是否变化">
        <template slot-scope="scope">
          <el-checkbox v-model="scope.row.status" :true-label="1" :false-label="0" disabled />
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->
  </div>
</template>

<script>
// import * as Axios from '@/api/settlement'
import { deepCopy } from '@/utils'
import { shineAsk, fourNum, maxLength } from '@/views/settlement/settlementToExamine/common'

export default {
  name: 'Materials',
  props: {
    loading: {
      type: Boolean,
      default: false
    },
    parentForm: {
      type: Object,
      default: () => {
        return {}
      }
    },
    ynEditqu: {
      type: Boolean,
      default: false
    },
    confirmButtonFooter: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      activeNames: 'Materials',
      tableData: [],
      total: 2,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      old: '',
      beforeTableData: []
    }
  },
  mounted() {
    // console.log(this.parentForm.urlParams, '==>')
    // this.getList()
  }
  // methods: {
  //   setChangeNum(val, row) {
  //     this.old = val.target.value
  //   },
  //   ynEditquDisAbleBegin(row, name) {
  //     if (this.confirmButtonFooter) return true
  //     if (name === 'changeNum') {
  //       if (row.usableStorage || row.unusableStorage || row.notUsableStorage || row.notUnusableStorage) {
  //         return true
  //       }
  //     }
  //     if (['usableStorage', 'unusableStorage', 'notUsableStorage', 'notUnusableStorage'].includes(name)) {
  //       if (row.changeNum) return true
  //     }
  //     let boo = true
  //     const first = ['changeNum', 'usableStorage', 'unusableStorage', 'notUsableStorage', 'notUnusableStorage', 'storemanNum', 'storageAddress']
  //     // eslint-disable-next-line eqeqeq
  //     if ((first.includes(name) || (name === 'storemanName' && row.fieldProjectManager == '1')) && row.proType == '0' && row.isPush == '0' && row.isPushAudit != '1' && row.outPutTypeCode != '25') {
  //       boo = false
  //     }
  //     return boo
  //   },
  //   ynEditquDisAble(row, column, cell, event) {
  //     let boo = true
  //     if (!this.ynEditqu) {
  //       boo = false
  //     } else {
  //       return true
  //     }
  //     const first = ['changeNum', 'usableStorage', 'unusableStorage', 'notUsableStorage', 'notUnusableStorage', 'storemanNum', 'storageAddress']
  //     // eslint-disable-next-line eqeqeq
  //     if ((first.includes(name) || (name === 'storemanName' && row.fieldProjectManager == '1')) && row.proType == '0' && row.isPush == '0' && row.isPushAudit != '1' && row.outPutTypeCode != '25') {
  //       boo = true
  //     }
  //     // eslint-disable-next-line eqeqeq
  //     if ((name == 'changeNum' && ((row.notUnusableStorage != '0' && row.notUnusableStorage != null && row.notUnusableStorage != undefined && row.notUnusableStorage != '') || (row.notUsableStorage != '0' && row.notUsableStorage != null && row.notUsableStorage != undefined && row.notUsableStorage != '') || (row.unusableStorage != '0' && row.unusableStorage != null && row.unusableStorage != undefined && row.unusableStorage != '') || (row.usableStorage != '0' && row.usableStorage != null && row.usableStorage != undefined && row.usableStorage != ''))) && row.proType == '0') {
  //       boo = false
  //     }
  //     const second = ['usableStorage', 'unusableStorage', 'notUsableStorage', 'notUnusableStorage']
  //     // eslint-disable-next-line eqeqeq
  //     if ((second.includes(name) && (row.changeNum != '0' && row.changeNum != null && row.changeNum != undefined && row.changeNum != '')) && row.proType == '0') {
  //       boo = false
  //     }
  //     const third = ['storemanName', 'storemanNum', 'storageAddress']
  //     // eslint-disable-next-line eqeqeq
  //     if ((third.includes(name) && (!row.notUsableStorage && !row.notUnusableStorage)) && row.proType == '0') {
  //       boo = false
  //     }
  //     return boo
  //   },
  //   getList() {
  //     Axios.getEquipList({ adjustId: this.parentForm.urlParams.adjustId }).then(res => {
  //       this.beforeTableData = deepCopy(res.data)
  //       this.tableData = res.data
  //     })
  //   },
  //   // 变化合价input 规则
  //   changePriceInput(value, row) {
  //     const data = row.row
  //     const a = value.toString().split('.')
  //     if (`${value}`.length >= 14) {
  //       data.changePrice = maxLength(value)
  //       return
  //     }
  //     if (a[1] && a[1].length > 4) {
  //       data.changePrice = fourNum(Number(value))
  //       return
  //     }
  //     // if (isNaN(value)) {
  //     //   this.$message.error('非法字符!')
  //     //   if (!data.donePrice) {
  //     //     data.changePrice = this.beforeTableData[row.$index].changePrice
  //     //     data.donePrice = this.beforeTableData[row.$index].donePrice
  //     //   } else {
  //     //     data.changePrice = ''
  //     //     data.equipSum = this.beforeTableData[row.$index].equipSum
  //     //     data.status = this.beforeTableData[row.$index].status
  //     //   }
  //     // } else {
  //     const s = this.$divide(Math.abs(data.changePrice), data.equipSum)
  //     const donePrice1 = this.$add(data.changePrice, data.equipSum)
  //     if (s > data.priceConfig) {
  //       this.$message.error('仅用于工程量调整引起的合价变化，严禁改变采购单价（变化超过' + data.priceConfig * 100 + '%）!')
  //       data.changePrice = 0
  //       if (!data.donePrice) {
  //         data.changePrice = ''
  //         data.equipSum = this.beforeTableData[row.$index].equipSum
  //         data.status = 1
  //       } else {
  //         data.changePrice = this.beforeTableData[row.$index].changePrice
  //         data.donePrice = this.beforeTableData[row.$index].donePrice
  //       }
  //     } else if (!data.changePrice) {
  //       data.status = 1
  //       data.donePrice = ''
  //       data.changePrice = this.beforeTableData[row.$index].changePrice
  //     } else {
  //       data.status = 1
  //       // 2-调增合价；3-调减合价
  //       data.changeStatus = data.changePrice > 0 ? '2' : '3'
  //       data.doneNum = data.amount
  //       data.donePrice = donePrice1
  //     }
  //     // }
  //   },
  //   // 电话号
  //   storemanNumInput(value, row) {
  //     const data = row.row
  //     data.status = 1
  //     data.storemanNum = maxLength(value, 11)
  //   },
  //   // 保管地址
  //   storageAddressInput(value, row) {
  //     const data = row.row
  //     data.status = 1
  //   },
  //   // 调增数量input 规则
  //   changeNumInput(val, row) {
  //     const data = row.row
  //     data.status = 0
  //     const value = data.changeNum
  //     if (!/^\d+(\.[0-9]{1,4})?$/.test(value)) {
  //       this.$message.error('输入不正确！只能输入最多四位小数的正数！')
  //       data.changeNum = this.old
  //       return
  //     }
  //     if (`${value}`.length >= 14) {
  //       data.changeNum = maxLength(value)
  //       return
  //     }
  //     const ifSinglePro = '0' // nui.get("ifSinglePro").getValue();//是否单项工程项目1时，0否
  //     const a = value.toString().split('.')
  //     if (a[1] && a[1].length > 4) {
  //       data['changeNum'] = fourNum(Number(value), Math.pow(10, 4))
  //       return
  //     }
  //     var proportion = 100
  //     const doneNum1 = this.$add(data.changeNum, data.amount)
  //     // 该类物资所有订单调整后的数量总和不允许超出该类物资设计方案中数量的120%
  //     var percentage01 = this.$add(data.percentage, 100)
  //     if (ifSinglePro === '0') {
  //       proportion = (Math.abs(parseFloat(data.changeNum) + parseFloat(data.amount)) / data.realAmount) * 100
  //       if (proportion > percentage01) {
  //         this.$message.error(`该类物资所有订单调整后的数量总和不允许超出该类物资设计方案中数量的${percentage01}%！`)
  //         data.changeNum = this.old
  //         return
  //       }
  //     }
  //     if (doneNum1 < 0) {
  //       this.$message.error('“变化后数量”的计算结果不能为负数！')
  //       data.changeNum = this.old
  //       return
  //     }
  //     if (!data.changeNum) {
  //       return
  //     }
  //     data.status = 1
  //     // 0-调增数量；1-调减数量；2-调增合价；3-调减合价
  //     data.changeStatus = data.changeNum > 0 ? '0' : '1'
  //     data.donePrice = this.$multiply(doneNum1, data.price)
  //     data.equipSum = !data.equipSum ? 0 : data.equipSum
  //     data.taxRate = !data.taxRate ? 0 : data.taxRate
  //     data.changePrice = this.$subtract(data.donePrice, data.equipSum)
  //     data.doneTaxAmount = this.$multiply(data.donePrice, data.taxRate)
  //     data.doneAmt = this.$add(data.donePrice, data.doneTaxAmount)
  //     data.doneNum = doneNum1
  //     data.changeNum = value
  //   },
  //   // proportion 值激素按
  //   proportionValue(data, ifSinglePro) {
  //     let proportion = '100'
  //     if (ifSinglePro === '0') {
  //       let doneNum2 = this.$add(data.changeNum, data.amount)
  //       const rows = this.beforeTableData.filter(item => {
  //         return data.scategoryCode === item.scategoryCode && data.siteId === item.siteId && (data.orderProductId !== item.orderProductId || data.sourceType !== item.sourceType)
  //       })
  //       for (var num = 0; num < rows.length; num++) {
  //         var doneNumber = rows[num].doneNum ? rows[num].amount : doneNumber // 调整后数量
  //         doneNum2 = this.$add(doneNum2, doneNumber)
  //       }
  //       proportion = this.$multiply(this.$divide(Math.abs(doneNum2), data.realAmount), 100)
  //     }
  //     return proportion
  //   },
  //   // 入库可用
  //   usableStorageInput(val, row, name) {
  //     const data = row.row
  //     const value = val.target.value
  //     // data[name] = value
  //     data.status = 1
  //     // const a = value.toString().split('.')
  //     // if (a[1] && a[1].length > data.spuUnitAcc) {
  //     //   data[name] = fourNum(Number(value), Math.pow(10, data.spuUnitAcc))
  //     //   return
  //     // }
  //     if (!/^\d+(\.[0-9]{1,4})?$/.test(value)) {
  //       this.$message.error('输入不正确！只能输入最多四位小数的正数！')
  //       data[name] = this.old
  //       if (name === 'notUsableStorage') {
  //         data.storemanName = ''
  //       }
  //       // if (data.doneNum) {
  //       //   data[name] = this.beforeTableData[row.$index][name]
  //       // } else {
  //       //   data.doneNum = ''
  //       //   data.donePrice = ''
  //       //   data.changePrice = ''
  //       //   data.changeStatus = ''
  //       //   data.doneAmt = ''
  //       //   data.doneTaxAmount = ''
  //       //   data[name] = this.old
  //       //   if (name === 'notUsableStorage') {
  //       //     data.storemanName = ''
  //       //   }
  //       // }
  //       return
  //     }
  //     if (!value) {
  //       this.valueFalse(data, name)
  //       return
  //     }
  //     const doneNum1 = this.doneNum1Value(data, name)
  //     if (doneNum1 < 0) {
  //       this.$message.error('“变化后数量”的计算结果不能为负数！')
  //       data[name] = this.old
  //       // data[name] = this.beforeTableData[row.$index][name]
  //       // data.doneNum = this.beforeTableData[row.$index].doneNum
  //       // data.changePrice = ''
  //       return
  //     }
  //     data.status = 1
  //     // 0-调增数量；1-调减数量；2-调增合价；3-调减合价
  //     data.changeStatus = '1'
  //     data.donePrice = this.$multiply(doneNum1, data.price)
  //     data.equipSum = data.equipSum || 0
  //     data.taxRate = data.taxRate || 0
  //     data.changePrice = this.$subtract(data.donePrice, data.equipSum)
  //     data.doneTaxAmount = this.$multiply(data.donePrice, data.taxRate)
  //     data.doneAmt = this.$add(data.donePrice, data.doneTaxAmount)
  //     data.doneNum = doneNum1
  //     if (['notUsableStorage', 'notUnusableStorage'].includes(name) && data.fieldProjectManager !== '1') {
  //       data.storemanName = data.fieldProjectManager
  //     }
  //   },
  //   doneNum1Value(data, name) {
  //     let doneNum1
  //     if (data.doneNum === '' || data.doneNum == null) {
  //       doneNum1 = this.$subtract(data.amount, data[name])
  //     } else {
  //       const usableStorage = data.usableStorage || 0
  //       const unusableStorage = data.unusableStorage || 0
  //       const notUsableStorage = data.notUsableStorage || 0
  //       const notUnusableStorage = data.notUnusableStorage || 0
  //       doneNum1 = this.$subtract([data.amount, usableStorage, notUsableStorage, notUnusableStorage, unusableStorage])
  //     }
  //     return doneNum1
  //   },
  //   valueFalse(data, name) {
  //     if (!data.doneNum) {
  //       data.doneNum = ''
  //       data.donePrice = ''
  //       data.changePrice = ''
  //       data.changeStatus = ''
  //       data.doneAmt = ''
  //       data.doneTaxAmount = ''
  //       data[name] = ''
  //       if (['notUsableStorage', 'notUnusableStorage'].includes(name)) {
  //         data.storemanName = ''
  //         data.storemanNum = ''
  //         data.storageAddress = ''
  //       }
  //       return
  //     }
  //     const usableStorage = data.usableStorage || 0
  //     const unusableStorage = data.unusableStorage || 0
  //     const notUsableStorage = data.notUsableStorage || 0
  //     const notUnusableStorage = data.notUnusableStorage || 0
  //     const sumNum = this.$add([usableStorage, unusableStorage, notUsableStorage, notUnusableStorage])
  //     const doneNum1 = this.$subtract([data.amount, unusableStorage, usableStorage, notUsableStorage, notUnusableStorage])
  //     // 记录“不入库（不可用不入库、可用不入库）”字段是否填写
  //     const notSunNum = this.$add(notUsableStorage, notUnusableStorage)
  //     if (sumNum > 0) {
  //       data.donePrice = this.$multiply(doneNum1, data.price)
  //       data.equipSum = data.equipSum || 0
  //       if (['notUsableStorage', 'usableStorage', 'notUnusableStorage'].includes(name)) {
  //         data.taxRate = data.taxRate || 0
  //       }
  //       data.storemanName = (['notUnusableStorage', 'notUsableStorage'].includes(name) && !(notSunNum > 0)) ? '' : data.storemanName
  //       data.changePrice = this.$subtract(data.donePrice, data.equipSum)
  //       data.doneTaxAmount = this.$multiply(data.donePrice, data.taxRate)
  //       data.doneAmt = this.$add(data.donePrice, data.doneTaxAmount)
  //       data.doneNum = doneNum1
  //       return
  //     }
  //     data.doneNum = ''
  //     data.donePrice = ''
  //     data.changePrice = ''
  //     data.changeStatus = ''
  //     data.doneAmt = ''
  //     data.doneTaxAmount = ''
  //     data[name] = ''
  //     data.storemanName = ''
  //     data.storemanNum = ''
  //     data.storageAddress = ''
  //   },
  //   shineAsk
  // }
}
</script>
<style scoped>
::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
  background-color: #eb4b4b;
}
</style>
